# coding: utf-8
from typing import Type, Optional, Any, Coroutine

from tortoise.models import MODEL

from core.base_db import BaseModel
from tortoise import fields, BaseDBAsyncClient


class ZhanUser(BaseModel):
    LOGIN_TYPE_LOCAL = 1

    USER_STATUS_OPEN = 1
    USER_STATUS_CLOSE = 2

    AUTHORITY_COMMON = 1
    AUTHORITY_ADMIN = 2

    email = fields.CharField(max_length=255, null=True, description="邮箱")
    username = fields.CharField(max_length=255, null=False, description="用户名")
    password = fields.CharField(max_length=255, description="密码")
    login_type = fields.IntField(default=1, description="登录类型")
    status = fields.IntField(default=USER_STATUS_OPEN, description="用户状态")
    authority = fields.IntField(default=AUTHORITY_COMMON, description="权限")
    user_phone = fields.CharField(max_length=255, description="手机号", null=True)

    class Meta:
        table = "zhan_user"


class ZhanMember(BaseModel):
    STATUS_OPEN = 1
    STATUS_CLOSE = 2
    user = fields.ForeignKeyField(model_name="models.ZhanUser")
    status = fields.IntField(default=STATUS_OPEN, description="会员状态")
    opening_time = fields.DatetimeField(auto_now_add=True)
    expiration_time = fields.DatetimeField()

    class Meta:
        table = "zhan_member"


class ZhanEmailCode(BaseModel):
    STATUS_NOT_VERIFY = 1
    STATUS_VERIFY = 2

    EMAIL_TYPE_REGISTER = 1
    EMAIL_TYPE_FORGOT = 2
    code = fields.CharField(max_length=255, description="验证码")
    status = fields.IntField(default=STATUS_NOT_VERIFY, description="状态")
    email = fields.CharField(max_length=255, description="邮件地址")
    email_type = fields.IntField(default=EMAIL_TYPE_REGISTER, description="邮件类型")

    class Meta:
        table = "zhan_email_code"


class ZhanFeedBack(BaseModel):
    suggest = fields.TextField(description="建议")
    app_bug = fields.TextField(description="bug")
    email = fields.CharField(max_length=255, description="邮箱")

    class Meta:
        table = "zhan_feedback"


class ZhanToken(BaseModel):
    user = fields.ForeignKeyField(model_name="models.ZhanUser", related_name="user")
    token = fields.TextField(description="token")

    class Meta:
        table = "zhan_token"
